package org.example.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.example.entity.Response;
import org.example.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.text.ParseException;


/**
 * @author ：jiangyaru
 * @date ：2024/4/6 22:42
 */
@RestController
@RequestMapping("/readLog")
@Api(tags = "1、读取日志文件")
public class testController {
    @Autowired
    LogService logService;

    @PostMapping(value = "/readLog", headers = "content-type=multipart/form-data")
    //swagger 的注解
    @ApiOperation(value = "日志文件分析", httpMethod = "POST", response =
            String.class, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "filename", value = "文件名字+userId", required = true),
            @ApiImplicitParam(name = "sTime", value = " 开始时间 (必传)(yyyy-MM-dd hh:mm:ss)",  required = false),
            @ApiImplicitParam(name = "eTime", value = "结束时间 (必传)(yyyy-MM-dd hh:mm:ss)",  required = false)
    }
    )
    public Response readLog(String filename, String sTime, String eTime, MultipartFile file) throws IOException {
        return logService.readLog(filename, sTime, eTime, file);
    }

    @PostMapping(value = "/queryPortHourTimes", headers = "content-type=multipart/form-data")
    //swagger 的注解
    @ApiOperation(value = " 查询时段接口调用次数", httpMethod = "POST", response =
            String.class, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sTime", value = " 开始时间 (必传)(yyyy-MM-dd hh:mm:ss)",  required = true),
            @ApiImplicitParam(name = "eTime", value = "结束时间 (必传)(yyyy-MM-dd hh:mm:ss)",  required = true)
    }
    )
    public Response queryPortHourTimes(String sTime, String eTime, MultipartFile file) throws IOException, ParseException {
        return logService.queryPortHourTimes(sTime, eTime, file);
    }
    @PostMapping(value = "/queryOnePortTimes", headers = "content-type=multipart/form-data")
    //swagger 的注解
    @ApiOperation(value = " 查询统计某一个接口在不同日期、不同小时的调用频次", httpMethod = "POST", response =
            String.class, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sTime", value = " 开始时间 (必传)(yyyy-MM-dd hh:mm:ss)",  required = true),
            @ApiImplicitParam(name = "eTime", value = "结束时间 (必传)(yyyy-MM-dd hh:mm:ss)",  required = true),
            @ApiImplicitParam(name = "portName", value = " 接口名称 (非必传)（可写多个， 逗号隔开）",  required = false)
    }
    )
    public Response queryOnePortTimes(String sTime, String eTime,String portName, MultipartFile file) throws IOException, ParseException {
        return logService.queryOnePortTimes(sTime, eTime, portName, file);
    }

    @PostMapping(value = "/queryOnePortTimesByUser", headers = "content-type=multipart/form-data")
    //swagger 的注解
    @ApiOperation(value = "  查询某用户在某时段内各个接口的调用频次", httpMethod = "POST", response =
            String.class, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sTime", value = " 开始时间 (必传)(yyyy-MM-dd hh:mm:ss)",  required = true),
            @ApiImplicitParam(name = "eTime", value = "结束时间 (必传)(yyyy-MM-dd hh:mm:ss)",  required = true),
            @ApiImplicitParam(name = "ip", value = " ip",  required = true)
    }
    )
    public Response queryOnePortTimesByUser(String sTime, String eTime,String ip, MultipartFile file) throws IOException, ParseException {
        return logService.queryOnePortTimesByUser(sTime, eTime, ip, file);
    }

}
